package com.duyutian.config;

import com.duyutian.model._MappingKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.MultipartConfigElement;

/**
 * Created by dyt on 2018/9/12.
 */
@Configuration
public class ActiveRecordConfig {

    @Value("${db.url}")
    private String url ;
    @Value("${db.username}")
    private String username ;
    @Value("${db.password}")
    private String password;

    @Bean
    public ActiveRecordPlugin activeRecord(){
        /*DruidPlugin dp = new DruidPlugin("jdbc:mysql://127.0.0.1:3306/hiwodyt?useUnicode=true&characterEncoding=UTF-8", "root", "123");*/
        DruidPlugin dp = new DruidPlugin(url, username, password);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        // 与 jfinal web 环境唯一的不同是要手动调用一次相关插件的start()方法
        //所有model添加
        _MappingKit.mapping(arp);
        dp.start();
        arp.start();
        return arp ;
    }
    //上传文件大小设置
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize("80MB"); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("102400KB");
        return factory.createMultipartConfig();
    }


}
